//
// Created on 4/3/2024.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".

#ifndef HARMONY_SPRINGSCROLLVIEWCOMPONENTINSTANCE_H
#define HARMONY_SPRINGSCROLLVIEWCOMPONENTINSTANCE_H

#include "RNOH/CppComponentInstance.h"
#include "SpringScrollViewNode.h"
#include "Props.h"
#include "ShadowNodes.h"
#include "Types.h"

namespace rnoh {
    class SpringScrollViewComponentInstance
        : public CppComponentInstance<facebook::react::RNCSpringScrollViewShadowNode>,public SpringScrollViewNodeDelegate {
    private:
        SpringScrollViewNode m_springStackNode;
        StackNode m_headerStackNode;
        StackNode m_scrollViewStackNode;
        StackNode m_footerStackNode;
        std::shared_ptr<const facebook::react::RNCSpringScrollViewEventEmitter> m_smartRefreshLayoutEventEmitter;

        Types::Offset initialContentOffset;
        Types::Offset contentOffset;
        Types::Size pageSize;
        Types::Size size;
        Types::Size contentSize;
        Types::Point lastPoint;
        Types::Point beginPoint;
        Types::EdgeInsets contentInsets;

        float refreshHeaderHeight = 0.0f;
        float loadingFooterHeight;
        float decelerationRate;
        bool bounces;
        bool scrollEnabled;
        bool inverted;
        bool allLoaded;
        bool directionalLockEnabled;
        bool pagingEnabled;

        bool isHeaderInserted{false};
        bool isFooterInserted{false};

    public:
        SpringScrollViewComponentInstance(Context context);
        void onChildInserted(ComponentInstance::Shared const &childComponentInstance, std::size_t index) override;
        void onChildRemoved(ComponentInstance::Shared const &childComponentInstance) override;
        SpringScrollViewNode &getLocalRootArkUINode() override;
        void onPropsChanged(SharedConcreteProps const &props) override;
        void getNapiProps(facebook::react::Props::Shared props);

        void setContentOffset(float x, float y);
        void setRefreshHeaderHeight(float height);
        void setLoadingFooterHeight(float height);
        void setAllLoaded(bool allLoaded);
        void setDecelerationRate(float rate);
        void setBounces(bool bounces);
        void setScrollEnabled(bool scrollEnabled);
        void setInitialContentOffset(float x, float y);
        void setInverted(bool inverted);
        void setDirectionalLockEnabled(bool directionalLockEnabled);
        void setPagingEnabled(bool pagingEnabled);
        void setPageSize(float width, float height);
    
        void scrollTo(float x, float y, bool animated);
        void endLoading(bool rebound);
        void endRefresh();

        void onRefresh() override;
        void onLoading() override;
        void onTouchBegin() override;
        void onTouchEnd() override;
        void onMomentumScrollBegin() override;
        void onMomentumScrollEnd() override;
        void onScroll() override;
        void onSizeChange() override;
        void onContentSizeChange() override;
    };
} // namespace rnoh

#endif // HARMONY_SpringScrollViewCOMPONENTINSTANCE_H
